package first.codeTop.alibaba;

/**
 * @ClassName LC151
 * @description:
 * @author: 荣燊
 * @create: 2021-10-19 21:35
 **/
public class LC151 {
    // 翻转字符串里的单词
    public static void main(String[] args) {
        String s = "  Bob    Loves  Alice   ";
        String[] s1 = s.trim().split(" ");
        for (String str : s1) {
            if (str.trim().length() != 0) {
                System.out.println(str);
                System.out.println("------——————————");
            }
        }
        System.out.println(reverseWords(s));
    }

    public static String reverseWords(String s) {
        StringBuffer stringBuffer = new StringBuffer();
        String[] s1 = s.trim().split(" ");
        for (int i=s1.length-1; i>=0; i--) {
            if (s1[i].trim().length() != 0) {
                stringBuffer.append(s1[i]+" ");
            }
        }
        return stringBuffer.toString().trim();
    }
}
